#pragma once

// Copyright (c) LordEvil - Licensed under GNU GPL
// For more information, see License.txt in the /wiki folder

/// EvilUpdater - EvilUpdater/evu-console/source/updl/downloader.hpp

// File Download SubSystem using WinInet

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
//// #include section ////
//////////////////////////

#include "../types.hpp"
#include <fstream>
#include <WinInet.h>
#include "../languages.hpp"

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
//// #code section ////
///////////////////////

class Downloader
{
	// Private
	static bool IsSupported(char *url); // Check if the type of the download is supported
    static unsigned long OpenFile(char *url, std::ofstream &fout); // Opens the file to download
    static bool GetFileName(char *url, char *fname); // Get the name of the file to download
	static void StatusUpdater(unsigned long part, unsigned long total, char *filename); // Updates the status of the download on the screen
	static HDOWNLOAD Basic_Download(char *url, bool useupdater); // Proper downloads the file - handles the 'medium-level' details

	void ErrorHandler(HDOWNLOAD error); // Handles the errors generated by 'download'

public:
	// Public
	bool download(char *url, bool UseErrorHandler = false, bool UseStatusUpdater = false); // Handles the 'high-level' details
};